import tableindex from "./tableindex"
import {ref}  from "vue"

// initFunc初始化生命周期的自定义函数，resetFunc弹窗关闭后的重置自定义函数，emitFunc关闭后抛出的自定义方法
export default (initFunc:null|Function=null,resetFunc:null|Function=null,emitFunc:null|Function=null) => {
    const { formValue,
        loading,
        total,
        tableData,
        editRef,
        pageRef,
        formRef,
        handleSearch,
        handleResetForm,
        handleView,
        handleEdit,
        handleCreate,
        refreshDelete } = tableindex()
    const formData = ref<any>({}) // 传递进来的数据
    const showModel = ref(false)    // 弹窗显示控制
    const handleInit=(data:any=null)=>{          // 初始化
        console.log("handleInit函数触发");  
        formData.value = {...data}      
        initFunc && initFunc(data);
        // 初始化的时候，定位第一页
        pageRef.value && pageRef.value.changePage({page:1,pageSize:20})
        showModel.value = true
    }
    const handleClose=()=>{         // 弹窗关闭
        showModel.value = false
        emitFunc && emitFunc()
        handleReset()
    }

    const handleReset=()=>{         // 弹窗重置
        resetFunc && resetFunc()
    }
    return {
        formValue,
        loading,
        total,
        tableData,
        editRef,
        pageRef,
        formRef,
        formData,
        showModel,
        handleSearch,
        handleResetForm,
        handleView,
        handleEdit,
        handleCreate,
        refreshDelete,handleInit,handleReset,handleClose,
    }
}